# Copyright (c) 2009 Barry Schwartz
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
# 
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

#--------------------------------------------------------------------------
import os
from os.path import abspath, join, splitext
from site_utilities import *

Import('*')

env = env.Clone()

lib_ext = get_library_extension(env)

#--------------------------------------------------------------------------

subdir_list = Split(
"""
Tools
Unicode
Logging
Trie
Bezier
Font
Runtime
Typesetting
VM
Engine
Markup
"""
)

for s in subdir_list:
    env['OCAMLINCLUDES'].append(abspath(subdirs[s]))

stubs = []
stubs.append(join(subdirs['Stubs'], 'kpathsea-stubs' + env['OBJSUFFIX']))
stubs.append(join(subdirs['Stubs'], 'unicode-tables' + env['OBJSUFFIX']))

flags = env['OCAMLFLAGS']
flags = flags + ['-linkpkg']
flags = flags + ['-package', 'dynlink']
flags = flags + ['-package', 'str']
flags = flags + ['-package', 'unix']
flags = flags + ['-package', 'camomile']
flags = flags + pycaml_flags
flags = flags + ['-cclib', kpathsea_libs]

if arithmetic_module == 'Gmp':
    flags = flags + ['-package', 'gmp']
    flags = flags + ['-cclib', '-lgmp -lmpfr']

env['OCAMLFLAGS'] = flags

objects = []
for s in subdir_list:
    for obj in obj_lists[s]:
        objects.append(obj)

main_obj = env.OCamlObject('Main')
bin = env.OCamlProgram(main_program, objects + main_obj + stubs)

Return('bin')

#--------------------------------------------------------------------------

# local variables:
# mode: python
# python-indent: 4
# end:
